package org.easytouseit.rabbitmq.service;

import org.easytouseit.rabbitmq.direct.DirectRabbitMQConfig;
import org.easytouseit.rabbitmq.fanout.FanoutRabbitMQConfig;
import org.easytouseit.rabbitmq.topic.consumer.TopicRabbitMQConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.UUID;

/**
 * @author guojm
 * @version V1.0
 * @date 2019-01-02 下午 17:26
 */
@Service("sendService")
public class SendService {
    private Logger logger = LoggerFactory.getLogger(this.getClass());


    @Resource
    private RabbitTemplate rabbitTemplate;
    public void sendDirectMsg(String content) {
        CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
        //把消息放入ROUTINGKEY_A对应的队列当中去，对应的是队列A
        rabbitTemplate.convertAndSend(DirectRabbitMQConfig.EXCHANGE_NAME, DirectRabbitMQConfig.ROUTING_KEY, content, correlationId);
    }
    public void sendTopicMsg1(String content) {
        CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
        //把消息放入ROUTINGKEY_A对应的队列当中去，对应的是队列A
        rabbitTemplate.convertAndSend(TopicRabbitMQConfig.TOPIC_EXCHANGE_NAME, TopicRabbitMQConfig.TOPIC_ROUTING_ONE, content, correlationId);
    }
    public void sendTopicMsg2(String content) {
        CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
        //把消息放入ROUTINGKEY_A对应的队列当中去，对应的是队列A
        rabbitTemplate.convertAndSend(TopicRabbitMQConfig.TOPIC_EXCHANGE_NAME, TopicRabbitMQConfig.TOPIC_ROUTING_TWO, content, correlationId);
    }
    public void sendFanoutMsg(String content) {
        CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
        //把消息放入ROUTINGKEY_A对应的队列当中去，对应的是队列A
        rabbitTemplate.convertAndSend(FanoutRabbitMQConfig.FANOUT_EXCHANGE_NAME, FanoutRabbitMQConfig.FANOUT_ROUTING_KEY, content, correlationId);
    }
    public void sendFanoutJson(Object content) {
        CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
        //把消息放入ROUTINGKEY_A对应的队列当中去，对应的是队列A
        rabbitTemplate.convertAndSend(FanoutRabbitMQConfig.FANOUT_EXCHANGE_NAME, FanoutRabbitMQConfig.FANOUT_ROUTING_KEY, content, correlationId);
    }
}
